home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Our Solar System
/
Our Solar System.iso
/
shuttle
/
seesat3
/
seesat.h
< prev
next >
Wrap
Text File
|
1990-12-24
|
11KB
|
385 lines
/*
SEESAT.H
by Paul S. Hirose, Edwards AFB, Calif., 1990 Nov 23
Declarations & definitions for globals in the SEESAT satellite tracking
program.
This file is in the public domain.
*/
/* If MAIN is defined, this header will generate definitions. Otherwise,
only declarations will be generated. */
#ifdef MAIN /* generate DEFINITIONS */
#define CLASS
#define EQUALS(N) = N
#else /* generate DECLARATIONS */
#define CLASS extern
#define EQUALS(N)
#endif
/*####################################################################
MISC DEPENDENCIES
####################################################################*/
#include <stdio.h>
/* POW(x, y) raises x to the y power. Both args are type double. */
#define POW(x, y) pow(x, y)
extern double pow();
/* ITOA(s, i) turns int i to a string at the location pointed
to by char pointer s. The return value from ITOA() is not used.
If you have no itoa(), try:
#define ITOA(s, i) sprintf(s, "%d", i)
int sprintf(); <-- your sprintf() may return a different type
*/
#define ITOA(s, i) itoa(s, i)
extern char *itoa();
/* JMPBUF defines (i.e., allocates space for) an object to be used by
setjmp() and longjmp(). SETJMP() and LONGJMP() must expand to calls to the
actual setjmp() and longjmp(). Here's how they're used in SEESAT:
JMPBUF s; define s as a "jump buffer"
SETJMP(s); store return location in s
LONGJMP(s, 1); execute jump to location stored in s, return 1
For ANSI C, I suggest the following:
#include <setjmp.h>
#define JMPBUF jmp_buf
#define SETJMP(s) setjmp(s)
#define LONGJMP(s, i) longjmp(s, i)
*/
/* for Ecosoft C */
#define JMPBUF jmp_env
#define SETJMP(s) setjmp(&s)
extern int setjmp();
#define LONGJMP(s, i) longjmp(&s, i)
extern void longjmp();
/* Nonzero enables precession correction to R.A./dec. Zero will eliminate
all precession code. */
#define ENPRE 1
/* MALLOC(n) returns a pointer to n bytes of storage, or NULL if insufficient
storage available. It need not clear the storage it allocates. In ANSI C:
#define MALLOC(n) malloc(n)
*/
#define MALLOC(n) alloc(n)
/* VOIDP is the type of arg required by free(). In ANSI C, do:
#define VOIDP void *
*/
#define VOIDP char *
/*####################################################################
Mathematical Constants
####################################################################*/
CLASS double
pi EQUALS(3.141592653589793),
e6a EQUALS(1e-6),
pio2 EQUALS(1.570796326794897), /* pi/2 */
tothrd EQUALS(.6666666666666667), /* 2/3 */
twopi EQUALS(6.283185307179586), /* 2pi */
x3pio2 EQUALS(4.712388980384690), /* 3pi/2 */
de2ra EQUALS(.0174532925199433), /* radians per degree */
ra2de EQUALS(57.29577951308232); /* deg per radian */
/*####################################################################
Physical Constants
####################################################################*/
/* dimensions & gravity of earth, World Geodetic System 1972 values */
CLASS double
xj2 EQUALS(1.082616e-3), /* 2nd gravitational zonal harmonic */
xj3, /* xj3, xj4 initialized at run time */
xj4,
ck2 EQUALS(5.41308E-4), /* .5 * xj2 */
ck4 EQUALS(6.2098875E-7), /* -.375 * xj4 */
xke EQUALS(.743669161e-1), /* = (G*M)^(1/2)*(er/min)^(3/2) where G =
Newton's grav const, M = earth mass */
xkmper EQUALS(6378.135), /* equatorial earth radius, km */
mean_r EQUALS(.998882406), /* mean radius, in units of xkmper */
/* SGP4/SGP8 density constants. qoms2t = ((qo - so) / xkmper) ** 4,
s = 1 + so / xkmper, where qo = 120 and so = 78 */
qoms2t EQUALS(1.88027916E-9),
s EQUALS(1.01222928),
xmnpda EQUALS(1440.0); /* time units/day */
/*####################################################################
Units & Conventions
####################################################################*/
/*
Unless the otherwise indicated, throughout this program
quantities are measured in the following units:
time interval minutes
epoch minutes since 4713 B.C. Jan 1 12h UT Julian
proleptic calendar
angle radians
length equatorial earth radii (1 unit = xkmper km)
South latitudes are negative.
East longitude is positive, west negative.
Azimuth is measured starting at north, increasing east.
*/
/*####################################################################
Structures
####################################################################*/
/* rectangular or spherical coordinates */
struct vector { double x, y, z; };
/* Julian date, time struct. CAUTION: jd is the jd at 12h, while time is
measured from 0h, 12h before. I.e., if s is a jdtim struct, you must
convert to epoch in minutes by doing: s.jd * 1440. + s.time - 720. */
struct jdtim {
long int jd; /* Julian date @ 12h */
double time; /* minutes since 0h */
};
/*####################################################################
Global Data
####################################################################*/
CLASS double
/* satellite's orbital elements. */
xmo, /* mean anomaly */
xnodeo, /* right ascension of ascending node */
omegao, /* argument of the perigee */
eo, /* eccentricity */
xincl, /* inclination */
xno, /* mean motion, radians/min */
xndt2o, /* 1st time derivative of mean motion, or ballistic
coefficient (depending on ephemeris type) */
xndd6o, /* 2nd time derivative of mean motion */
bstar, /* BSTAR drag term if GP4 theory was used;
otherwise, radiation pressure coefficient */
epoch, /* epoch of elements */
ds50, /* days since 1950 */
zd, /* UTC - local time */
toffs; /* value of OFFSET command */
/* Satellite geocentric position and velocity. Generated by the
prediction model. */
CLASS struct vector sat, satdot;
/* The following data come from xyztop() */
CLASS struct vector
azel, /* azimuth, elevation, slant range */
radec, /* Right Ascension, declination, slant range */
latlon; /* longitude, latitude, altitude */
CLASS int elsusa; /* elev of sun above sat's horizon, degrees */
CLASS JMPBUF reset; /* used by LONGJMP() to return control
to user in case of erroneous command */
CLASS int iflag; /* = 1 with new orbital elements,
reset to 0 by prediction model on first call */
CLASS char **tokp; /* pointer to command line tokens */
CLASS char name[23]; /* of satellite */
/*######################### Functions #########################*/
/*========================== ASTRO.C =========================*/
extern void dusk(); /* no args
prints azimuth & elevation of sun at observer. */
extern double fmod2p(); /* (x)
double x;
Returns x modulo 2pi */
extern void inpre(); /* no args
initializes the precession rotation matrix */
extern void moon(); /* no args
prints az, el, % of illum of moon */
extern void parall(); /* no args
prints the parallactic angle at the sat */
extern void setep(); /* no args
sets new terminal epoch for precession */
extern double thetag(); /* (t)
double t; epoch
Returns Greenwich hour angle of Aries at t & sets ds50 */
extern double topos(); /* no args
gets observer's location. Returns time zone offset */
extern int xyztop(); /* (t)
double t; epoch
computes topocentric coordinates of sat, return 1 if data should be
printed. */
/*========================= READEL.C =========================*/
extern void hfree(); /* no args
frees all heap storage */
extern void index(); /* no args
lists satellites in the open element file */
extern void load(); /* no args
Loads orbital elements from the open element file */
extern void opn(); /* no args
opens element file */
/*========================== SGP4.C ==========================*/
extern void sgp4(); /* (tsince)
double tsince; elapsed time since epoch of elements
generates geocentric (x, y, z) of satellite */
/*========================== UTIL.C ==========================*/
extern double atomin(); /* (string)
char *string;
convert string to minutes */
extern char **degdms(); /* (pre, x)
int pre; desired precision
double x; degrees
convert x to deg, minutes, seconds strings */
extern double din(); /* (str)
char *str;
input a double from console, str is default value */
extern char *jdstr(); /* (jd)
long int jd;
converts jd to year, month, day in string form */
extern long int julday(); /* (y, m, d)
int y, m, d;
returns JD (unit = days) of given year, month, day @ 12h */
extern char *stoup(); /* (str)
char *str;
converts str to all upper case, returns str */
extern char *timstr(); /* (m)
double m; minutes
converts m to string of "hhmm:ss" format */
extern void tok(); /* no args
gets new command line if current one exhausted */
extern void tokjum(); /* (t)
struct jdtim *t; destination of result
converts date/time group on command line to JD & minutes */
extern double tokmin(); /* no args
converts date/time group on cmd line to epoch in minutes */
/*#################### DEBUGGING FUNCTIONS ####################*/
/* DEBUG is controlled in the file that #includes this file. */
#ifdef DEBUG
#define DTEST(a) ddebug a
#define ETEST(a) edebug a
#define FTEST(a) fdebug a
extern void ddebug(), edebug(), fdebug();
#ifdef MAIN
/* Debugging functions. This stuff is only activated when
SEESAT.C is compiled with DEBUG on. Each function printf()s a
variable number of arguments of a particular type. If the bp
argument passed to the function matches variable stopat, the
arguments are printf() all on the same line. If bp != stopat, no
action occurs. The arguments to be printed are passed by
reference, and the number of arguments is given by argc. */
static int stopat; /* currently active break point */
void
ddebug(bp, argc, arg1)
int bp, argc, *arg1;
{
if (bp == stopat) {
int **argptr;
printf("%d: ", bp);
for (argptr = &arg1; argc ; ++argptr, --argc)
printf("%d ", **argptr);
getbp();
} }
void
edebug(bp, argc, prec, arg1)
int bp, argc, prec;
double *arg1;
{
if (bp == stopat) {
double **argptr;
printf("%d: ", bp);
for (argptr = &arg1; argc; ++argptr, --argc)
printf("%.*e ", prec, **argptr);
getbp();
} }
void
fdebug(bp, argc, prec, arg1)
int bp, argc, prec;
double *arg1;
{
if (bp == stopat) {
double **argptr;
printf("%d: ", bp);
for (argptr = &arg1; argc; ++argptr, --argc)
printf("%.*f ", prec, **argptr);
getbp();
} }
static void
getbp()
/* ask for next breakpoint, put value in stopat */
{
char buffer[7];
printf("\nnext breakpoint? ");
stopat = atoi(gets(buffer));
}
#endif
#else
/* Debugging is turned off, so expand the macros to nothing */
#define DTEST(a)
#define ETEST(a)
#define FTEST(a)
#endif
int */
void
ddebug(bp, argc, arg1)
int bp, argc, *arg1;
{
if (bp == stopat) {
int **argptr;
printf("%d: